﻿#if Xlua

#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System.IO;

public static class XluaTool
{

    

    [MenuItem("Plateface/Xlua/CopyXlua to byte", false, 1)]
    public static void CopyXlua()
    {
        string xlua = Path.Combine(Application.dataPath, XluaMa.luaPath);
        string newXluaPath = Path.Combine(Application.dataPath, "bawAsset/Xlua/");

        DirectoryCopy(xlua, newXluaPath);


    }


    private static void DirectoryCopy(string sourceDirName, string destDirName)
    {
        // If the destination directory doesn't exist, create it.
        if (!Directory.Exists(destDirName))
        {
            Directory.CreateDirectory(destDirName);
        }

        foreach (string folderPath in Directory.GetDirectories(sourceDirName, "*", SearchOption.AllDirectories))
        {
            if (!Directory.Exists(folderPath.Replace(sourceDirName, destDirName)))
                Directory.CreateDirectory(folderPath.Replace(sourceDirName, destDirName));
        }

        foreach (string filePath in Directory.GetFiles(sourceDirName, "*.lua", SearchOption.AllDirectories))
        {
            string fileName = Path.GetFileName(filePath);
            int index = fileName.LastIndexOf(".");
            string byteFileName = fileName.Substring(0, index) + ".bytes";
            string dirName = Path.GetDirectoryName(filePath) + "/";
            string bytePath = dirName.Replace(sourceDirName, destDirName) + "/";
            string newFilePath = Path.Combine(bytePath,byteFileName);

            File.Copy(filePath, newFilePath, true);
        }
    }
}
#endif

#endif